package com.ymatou.iapi.livebuyer.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.ymatou.iapi.livebuyer.parameter.GetShutUpInLiveRoomBean;
import com.ymatou.iapi.livebuyer.service.GetShutUpInLiveRoomCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.utils.TestDataManager;
/**
*获取直播间禁言列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetShutUpInLiveRoom{
	private static GetShutUpInLiveRoomBean getshutupinliveroomBean;
	private static GetShutUpInLiveRoomCall getshutupinliveroomCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取直播间禁言列表");
	}

	@Before
	public void caseUp() {
		getshutupinliveroomBean=new GetShutUpInLiveRoomBean();
		getshutupinliveroomCall=new GetShutUpInLiveRoomCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getshutupinliveroomCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetShutUpInLiveRoom_001() {
		Logger.start(true,"获取直播间禁言列表成功");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			List<Integer> uids=new ArrayList<Integer>();
			int liveid = livedto.getId();
			for (int i = 1; i <2; i++) {
				uids.add(i);
			}
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			for (Integer uid : uids) {
				LiveRoomCallService.enterGroup(liveid, uid);
				LiveRoomCallService.ShutUpInLiveRoom(liveid, livedto.getUserId(), uid);
			}
			getshutupinliveroomBean.setLiveId(liveid);
			getshutupinliveroomCall.setData(getshutupinliveroomBean);
			getshutupinliveroomCall.callService();			
			Logger.verifyEquals("200", getshutupinliveroomCall.getString("code"), "验证code");
			JsonArray ja = getshutupinliveroomCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(uids.size(), ja.size(), "验证禁言条数");
			ja.forEach(json->{
				Logger.verifyEquals(true, uids.contains(json.getAsJsonObject().get("memberAccount").getAsInt()), "验证memberAccount");
				Logger.verifyNotNull(json.getAsJsonObject().get("shuttedUntil"),"验证shuttedUntil");
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetShutUpInLiveRoom_002() {
		Logger.start(true,"不输入liveId失败");
		try {
			getshutupinliveroomCall.setData(getshutupinliveroomBean);
			getshutupinliveroomCall.callService();			
			Logger.verifyEquals("100", getshutupinliveroomCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetShutUpInLiveRoom_003() {
		Logger.start(true,"输入liveId错误失败");
		try {
			getshutupinliveroomBean.setLiveId(-1);
			getshutupinliveroomCall.setData(getshutupinliveroomBean);
			getshutupinliveroomCall.callService();			
			Logger.verifyEquals("100", getshutupinliveroomCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	//需要在腾讯云通讯有记录的用户id才能成功-记录是手机客户端发送
	public void Tc_GetShutUpInLiveRoom_004() {
		Logger.start(true,"获取直播间禁言列表成功,有多条记录");
		try {
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			List<Integer> uids=new ArrayList<Integer>();
			int liveid = livedto.getId();
			for (int i = 1; i <4; i++) {
				uids.add(i);
			}
			LiveRoomCallService.SellerLiveOnline(liveid, livedto.getUserId());
			for (Integer uid : uids) {
				LiveRoomCallService.enterGroup(liveid, uid);
				LiveRoomCallService.ShutUpInLiveRoom(liveid, livedto.getUserId(), uid);
			}
			getshutupinliveroomBean.setLiveId(liveid);
			getshutupinliveroomCall.setData(getshutupinliveroomBean);
			getshutupinliveroomCall.callService();			
			Logger.verifyEquals("200", getshutupinliveroomCall.getString("code"), "验证code");
			JsonArray ja = getshutupinliveroomCall.getJsonObject().get("data").getAsJsonArray();
			Logger.verifyEquals(uids.size(), ja.size(), "验证禁言条数");
			ja.forEach(json->{
				Logger.verifyEquals(true, uids.contains(json.getAsJsonObject().get("memberAccount").getAsInt()), "验证memberAccount");
				Logger.verifyNotNull(json.getAsJsonObject().get("shuttedUntil"),"验证shuttedUntil");
			});		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}